home *** CD-ROM | disk | FTP | other *** search
/ All for Cell Phones: Sony Ericsson / Sony-Ericsson 2004.iso / Java / DateToDate / DateToDate.jar / DateToDate.class (.txt) next >
Encoding:
Java Class File  |  2001-09-04  |  5.2 KB  |  135 lines

  1. import java.io.IOException;
  2. import java.util.Calendar;
  3. import java.util.Date;
  4. import javax.microedition.lcdui.Command;
  5. import javax.microedition.lcdui.CommandListener;
  6. import javax.microedition.lcdui.DateField;
  7. import javax.microedition.lcdui.Display;
  8. import javax.microedition.lcdui.Displayable;
  9. import javax.microedition.lcdui.Form;
  10. import javax.microedition.lcdui.Image;
  11. import javax.microedition.lcdui.ImageItem;
  12. import javax.microedition.lcdui.StringItem;
  13. import javax.microedition.midlet.MIDlet;
  14.  
  15. public class DateToDate extends MIDlet implements CommandListener {
  16.    private Display display = Display.getDisplay(this);
  17.    private Form helpForm;
  18.    private Form openingForm = new Form("");
  19.    private Form mainForm;
  20.    private Form resultForm;
  21.    private Command nextCommand = new Command("Next", 4, 1);
  22.    private Command helpCommand = new Command("Help", 4, 1);
  23.    private Command backCommand = new Command("Back", 4, 1);
  24.    private Command exitCommand = new Command("Exit", 4, 2);
  25.    private Command computeCommand = new Command("Compute", 4, 1);
  26.    private StringItem helpStringItem;
  27.    private StringItem openingStringItem;
  28.    private StringItem resultStringItem;
  29.    private DateField fromDF;
  30.    private DateField toDF;
  31.    private Image img;
  32.    private ImageItem imgItem;
  33.  
  34.    public DateToDate() {
  35.       try {
  36.          this.img = Image.createImage("/looach.png");
  37.          this.imgItem = new ImageItem("", this.img, 0, "[TIME_TABLE]");
  38.          this.openingForm.append(this.imgItem);
  39.       } catch (IOException var2) {
  40.          ((Throwable)var2).printStackTrace();
  41.       }
  42.  
  43.       this.openingStringItem = new StringItem("DateToDate v1.1Beta\nwas developed by", "\nJACADO\nwww.jacado.com\nThis software is provided \"AS IS\", without warranty of any kind. In no event, shell we be liable for any claim, damages or other liability. Copyright(c)2001 Haim Michael, JACADO & ZINDELL Ltd. All rights reserved.");
  44.       this.openingForm.append(this.openingStringItem);
  45.       this.openingForm.addCommand(this.nextCommand);
  46.       this.openingForm.addCommand(this.helpCommand);
  47.       this.openingForm.setCommandListener(this);
  48.       this.display.setCurrent(this.openingForm);
  49.       this.helpForm = new Form("Help");
  50.       this.helpStringItem = new StringItem("Instructions", " This midlet computes the difference (in days) between two dates. You should choose two dates an press \"Compute\".");
  51.       this.helpForm.append(this.helpStringItem);
  52.       this.helpForm.addCommand(this.backCommand);
  53.       this.helpForm.setCommandListener(this);
  54.       this.mainForm = new Form("DateToDate");
  55.       this.fromDF = new DateField("From", 1);
  56.       this.toDF = new DateField("To", 1);
  57.       Date temp = Calendar.getInstance().getTime();
  58.       this.fromDF.setDate(temp);
  59.       this.toDF.setDate(temp);
  60.       this.mainForm.append(this.fromDF);
  61.       this.mainForm.append(this.toDF);
  62.       this.mainForm.addCommand(this.exitCommand);
  63.       this.mainForm.addCommand(this.computeCommand);
  64.       this.mainForm.setCommandListener(this);
  65.       this.resultForm = new Form("Result");
  66.       this.resultStringItem = new StringItem("The difference between the two dates is", " 0 days");
  67.       this.resultForm.append(this.resultStringItem);
  68.       this.resultForm.addCommand(this.exitCommand);
  69.       this.resultForm.addCommand(this.backCommand);
  70.       this.resultForm.setCommandListener(this);
  71.    }
  72.  
  73.    public void commandAction(Command c, Displayable d) {
  74.       if (d == this.openingForm) {
  75.          if (c == this.helpCommand) {
  76.             this.display.setCurrent(this.helpForm);
  77.          } else if (c == this.nextCommand) {
  78.             this.display.setCurrent(this.mainForm);
  79.          }
  80.       } else if (d == this.helpForm) {
  81.          if (c == this.backCommand) {
  82.             this.display.setCurrent(this.openingForm);
  83.          }
  84.       } else if (d == this.mainForm) {
  85.          if (c == this.exitCommand) {
  86.             this.exit();
  87.          } else if (c == this.computeCommand) {
  88.             long fromTemp = this.fromDF.getDate().getTime();
  89.             long toTemp = this.toDF.getDate().getTime();
  90.             long days = (toTemp - fromTemp) / 86400000L;
  91.             this.resultStringItem.setText(" " + days + " days");
  92.             this.display.setCurrent(this.resultForm);
  93.          }
  94.       } else if (d == this.resultForm) {
  95.          if (c == this.exitCommand) {
  96.             this.exit();
  97.          } else if (c == this.backCommand) {
  98.             this.display.setCurrent(this.mainForm);
  99.          }
  100.       }
  101.  
  102.    }
  103.  
  104.    public void exit() {
  105.       this.destroyApp(true);
  106.       ((MIDlet)this).notifyDestroyed();
  107.    }
  108.  
  109.    public void startApp() {
  110.       System.out.println("in startApp()");
  111.    }
  112.  
  113.    public void pauseApp() {
  114.       System.out.println("in pause()");
  115.    }
  116.  
  117.    public void destroyApp(boolean cond) {
  118.       this.display = null;
  119.       this.helpForm = null;
  120.       this.openingForm = null;
  121.       this.mainForm = null;
  122.       this.resultForm = null;
  123.       this.nextCommand = null;
  124.       this.helpCommand = null;
  125.       this.backCommand = null;
  126.       this.exitCommand = null;
  127.       this.computeCommand = null;
  128.       this.helpStringItem = null;
  129.       this.openingStringItem = null;
  130.       this.resultStringItem = null;
  131.       this.img = null;
  132.       this.imgItem = null;
  133.    }
  134. }
  135.